<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html class="no-js fixed-layout">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Listen 美食城|美味小吃|营养丰富</title>
  <meta name="description" content="这是一个 index 页面">
  <meta name="keywords" content="index">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="icon" type="image/png" href="/Public/vendor/assets/i/favicon.png">
  <link rel="apple-touch-icon-precomposed" href="/Public/vendor/assets/i/app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-title" content="Amaze UI" />
  <link rel="stylesheet" href="/Public/vendor/assets/css/amazeui.min.css"/>
  <link rel="stylesheet" href="/Public/vendor/assets/css/admin.css">
  <link rel="stylesheet" href="/Public/vendor/nprogress/nprogress.css">

  
</head>
<body>
<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，Amaze UI 暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a>
  以获得更好的体验！</p>
<![endif]-->

<header class="am-topbar am-topbar-inverse admin-header">
    <div class="am-topbar-brand">
        <strong>Listen 美食城</strong> <small>后台管理模板</small>
    </div>

    <button class="am-topbar-btn am-topbar-toggle am-btn am-btn-sm am-btn-success am-show-sm-only" data-am-collapse="{target: '#topbar-collapse'}"><span class="am-sr-only">导航切换</span> <span class="am-icon-bars"></span></button>

    <div class="am-collapse am-topbar-collapse" id="topbar-collapse">

        <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list">
            <li><a href="javascript:;"><span class="am-icon-envelope-o"></span> 收件箱 <span class="am-badge am-badge-warning">5</span></a></li>
            <li class="am-dropdown" data-am-dropdown>
                <a class="am-dropdown-toggle" data-am-dropdown-toggle href="javascript:;">
                    <span class="am-icon-users"></span> <?php echo ($_SESSION[user]['username']); ?>管理员 <span class="am-icon-caret-down"></span>
                </a>
                <ul class="am-dropdown-content">
                    <li><a href="#"><span class="am-icon-user"></span> 资料</a></li>
                    <li><a href="#"><span class="am-icon-cog"></span> 设置</a></li>
                    <li><a href="<?php echo U('User/logout');?>"><span class="am-icon-power-off"></span> 退出</a></li>
                </ul>
            </li>
            <li class="am-hide-sm-only"><a href="javascript:;" id="admin-fullscreen"><span class="am-icon-arrows-alt"></span> <span class="admin-fullText">开启全屏</span></a></li>
        </ul>
    </div>
</header>


<div class="am-cf admin-main">
  <!-- sidebar start -->
  <div class="admin-sidebar am-offcanvas" id="admin-offcanvas">
    <div class="am-offcanvas-bar admin-offcanvas-bar">
        <ul class="am-list admin-sidebar-list">
            <li><a href="/admin"><span class="am-icon-home"></span> 首页</a></li>
            <li class="admin-parent">
                <a class="am-cf" data-am-collapse="{target: '#collapse-nav'}"><span class="am-icon-product-hunt am-icon-spin"></span> 商城中心
                    <span class="am-icon-angle-right am-fr am-margin-right"></span></a>
                <ul class="am-list am-collapse admin-sidebar-sub am-in" id="collapse-nav">
                    <li><a href="<?php echo U('Product/index');?>" class="am-cf"><span class="am-icon-shopping-cart"></span> 商品列表<span
                            class="am-badge am-badge-success am-margin-right am-fr"><?php echo ($product_counts); ?></span></a></li>
                    <!--<li><a href="<?php echo U('Product/add');?>"><span class="am-icon-puzzle-piece"></span> 商品管理</a></li>-->
                    <li><a href="<?php echo U('Category/index');?>"><span class="am-icon-calendar"></span> 分类管理</a></li>
                    <li><a href="<?php echo U('Gallery/index');?>"><span class="am-icon-photo"></span> 商品相册<span
                            class="am-badge am-badge-secondary am-margin-right am-fr">12</span></a></li>
                    <li><a href="<?php echo U('Advert/index');?>"><span class="am-icon-adjust"></span> 广告管理<span
                            class="am-badge am-badge-secondary am-margin-right am-fr"><?php echo ($advert_counts); ?></span></a></li>
                    <li><a href="<?php echo U('Customer/index');?>"><span class="am-icon-user-secret"></span> 会员管理<span
                            class="am-badge am-badge-secondary am-margin-right am-fr"><?php echo ($customer_counts); ?></span></a></li>
                    <li><a href="<?php echo U('Order/index');?>"><span class="am-icon-arrow-circle-o-right"></span> 订单管理<span
                            class="am-badge am-badge-success am-margin-right am-fr"><?php echo ($order_counts); ?></span></a></li>
                    <li><a href="<?php echo U('Recycle/index');?>"><span class="am-icon-refresh"></span> 商品回收站<span
                            class="am-badge am-badge-warning am-margin-right am-fr"><?php echo ($product_recycles); ?></span></a></li>
                </ul>
            </li>
            <li class="admin-parent">
                <a class="am-cf" data-am-collapse="{target: '#collapse-auth'}"><span class="am-icon-gear am-icon-spin"></span> 系统管理
                    <span class="am-icon-angle-right am-fr am-margin-right"></span></a>
                <ul class="am-list am-collapse admin-sidebar-sub am-in" id="collapse-auth">
                    <li><a href="<?php echo U('AuthSet/user_manage');?>"><span class="am-icon-user"></span> 用户管理
                        <span class="am-badge am-badge-success am-margin-right am-fr"><?php echo ($user_counts); ?></span></a></li>
                    <li><a href="<?php echo U('AuthSet/group_manage');?>"><span class="am-icon-group"></span> 用户组管理</a></li>
                    <li><a href="<?php echo U('AuthSet/rule_manage');?>" class="<?php echo ($_menu or ''); ?>"><span class="am-icon-lock"></span> 菜单与权限</a></li>
                </ul>
            </li>
        </ul>

        <div class="am-panel am-panel-default admin-sidebar-panel">
            <div class="am-panel-bd">
                <p><span class="am-icon-bookmark"></span> 公告</p>
                <p>时光静好，与君语；细水流年，与君同。—— Amaze UI</p>
            </div>
        </div>

        <div class="am-panel am-panel-default admin-sidebar-panel">
            <div class="am-panel-bd">
                <p><span class="am-icon-tag"></span> wiki</p>
                <p>Welcome to the Amaze UI wiki!</p>
            </div>
        </div>
    </div>
</div>

  <!-- sidebar end -->

  <!-- content start -->
  
    <div class="admin-content">
        <form class="am-form" action="<?php echo U('edit',['id'=>$product[id]]);?>" method="post">

            <div class="admin-content-body">
                <div class="am-cf am-padding am-padding-bottom-0">
                    <div class="am-fl am-cf">
                        <strong class="am-text-primary am-text-lg">编辑商品</strong> /
                        <small>Edit List</small>
                    </div>
                </div>

                <hr>

                <div class="am-tabs am-margin" data-am-tabs>
                    <ul class="am-tabs-nav am-nav am-nav-tabs">
                        <li class="am-active"><a href="#tab1">基本信息</a></li>
                        <li><a href="#tab2">详细描述</a></li>
                        <li><a href="#tab3">商品相册</a></li>
                    </ul>

                    <div class="am-tabs-bd">
                        <div class="am-form  am-tab-panel am-fade am-in am-active" id="tab1">
                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">所属类别</div>
                                <div class="am-u-sm-8 am-u-md-3 am-u-end col-end">
                                    <select data-am-selected="{btnWidth: '100%',  btnStyle: 'secondary', btnSize: 'sm', maxHeight: 360, searchBox: 1}"
                                            name="category_id">
                                        <?php if(is_array($categories)): $i = 0; $__LIST__ = $categories;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$category): $mod = ($i % 2 );++$i;?><option value="<?php echo ($category["id"]); ?>" disabled><?php echo ($category["name"]); ?></option>
                                            <?php if(is_array($category["children"])): $i = 0; $__LIST__ = $category["children"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$child): $mod = ($i % 2 );++$i;?><option value="<?php echo ($child["id"]); ?>"
                                                <?php if(($child["id"]) == $product["category_id"]): ?>selected<?php endif; ?>
                                                >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|--<?php echo ($child["name"]); ?>
                                                </option><?php endforeach; endif; else: echo "" ;endif; endforeach; endif; else: echo "" ;endif; ?>
                                    </select>
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                    名称
                                </div>
                                <div class="am-u-sm-8 am-u-md-3 am-u-end col-end">
                                    <input type="text" required rangelength="2,20" value="<?php echo ($product["name"]); ?>" name="name"
                                           class="am-input-sm">
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                    价格
                                </div>
                                <div class="am-u-sm-8 am-u-md-3 am-u-end col-end">
                                    <input type="text" required name="price" value="<?php echo ($product["price"]); ?>"
                                           class="am-input-sm">
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                    库存
                                </div>
                                <div class="am-u-sm-8 am-u-md-3 am-u-end col-end">
                                    <input type="text" name="stock" value="<?php echo ($product["stock"]); ?>" class="am-input-sm">
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                    缩略图
                                </div>
                                <div class="am-u-sm-8 am-u-md-10">
                                    <div class="upload_one am-icon-cloud-upload am-btn am-btn-default"></div>
                                    <div class="view_one">
                                        <input type="hidden" name="thumb" value="<?php echo ($product["thumb"]); ?>">
                                        <img src="<?php echo ($product["thumb"]); ?>" class="am-img-responsive"
                                             style="margin-top: 8px;max-height: 60px;">
                                    </div>
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">是否上架</div>
                                <div class="am-u-sm-8 am-u-md-10">
                                    <label>
                                        <input type="radio" value="1" name="is_onsale"
                                        <?php if(($product["is_onsale"]) == "1"): ?>checked<?php endif; ?>
                                        > 是
                                    </label>
                                    <label>
                                        <input type="radio" value="0" name="is_onsale"
                                        <?php if(($product["is_onsale"]) == "0"): ?>checked<?php endif; ?>
                                        > 否
                                    </label>
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                    发布时间
                                </div>
                                <div class="am-u-sm-8 am-u-md-3 am-u-end col-end">
                                    <div class="am-input-group am-datepicker-date"
                                         data-am-datepicker="{format: 'yyyy-mm-dd'}">
                                        <input type="text" name="created_at"
                                               value="<?php echo (date('Y-m-d',$product["created_at"])); ?>" class="am-form-field"
                                               placeholder="请输入日期"
                                               readonly>
                                        <span class="am-input-group-btn am-datepicker-add-on">
                                        <button class="am-btn am-btn-default" type="button">
                                            <span class="am-icon-calendar"></span>
                                        </button>
                                    </span>
                                    </div>
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">推荐类型</div>
                                <div class="am-u-sm-8 am-u-md-10">
                                    <div class="am-btn-group" data-am-button>
                                        <label class="am-btn am-btn-default am-btn-xs">
                                            <input type="checkbox" name="is_top"
                                            <?php if(($product["is_top"]) == $product["is_top"]): ?>checked<?php endif; ?>
                                            > 置顶
                                        </label>
                                        <label class="am-btn am-btn-default am-btn-xs">
                                            <input type="checkbox" name="is_new"
                                            <?php if(($product["is_top"]) == $product["is_new"]): ?>checked<?php endif; ?>
                                            > 新品
                                        </label>
                                        <label class="am-btn am-btn-default am-btn-xs">
                                            <input type="checkbox" name="is_hot"
                                            <?php if(($product["is_top"]) == $product["is_hot"]): ?>checked<?php endif; ?>
                                            > 热卖
                                        </label>
                                        <label class="am-btn am-btn-default am-btn-xs">
                                            <input type="checkbox" name="is_recommend"
                                            <?php if(($product["is_top"]) == $product["is_recommend"]): ?>checked<?php endif; ?>
                                            > 推荐
                                        </label>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="am-form am-tab-panel am-fade" id="tab2">

                            <div class="am-g am-margin-top-sm">
                                <div class="am-u-sm-12 am-u-md-2 am-text-right admin-form-text">
                                    内容描述
                                </div>
                                <div class="am-u-sm-12 am-u-md-10">

                                    <!-- 加载编辑器的容器 -->
                                    <textarea id="container" name="description" type="text/plain"><?php echo ($product["description"]); ?>
                                    </textarea>
                                </div>
                            </div>
                        </div>

                        <div class="am-form am-tab-panel am-fade" id="tab3">
                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                    商品相册
                                </div>
                                <div class="am-u-sm-12 am-u-md-10">
                                    <div id="upload_more" class="am-icon-cloud-upload am-btn am-btn-default"></div>
                                    <div id="view_more"></div>
                                </div>

                                <?php if(is_array($galleries)): $i = 0; $__LIST__ = $galleries;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$gallery): $mod = ($i % 2 );++$i;?><span class="img-box">
                                        <img class="img img-responsive" width="80" src="<?php echo ($gallery["img"]); ?>">
                                        <a class="label label-danger remove-picture" href="javascript:void(0);">删除
                                        </a>
                                        <input type="hidden" name="gallery[]" value="<?php echo ($gallery["id"]); ?>">
                                    </span><?php endforeach; endif; else: echo "" ;endif; ?>

                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="am-margin">
                <button type="submit" class="am-btn am-btn-primary am-btn-xs">提交保存</button>
                <button type="reset" class="am-btn am-btn-warning am-btn-xs">放弃保存</button>
            </div>
        </form>
    </div>


    <footer class="admin-content-footer">
        <hr>
        <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
    </footer>

  <!-- content end -->

</div>

<a href="#" class="am-icon-btn am-icon-th-list am-show-sm-only admin-menu" data-am-offcanvas="{target: '#admin-offcanvas'}"></a>


<!--[if (gte IE 9)|!(IE)]><!-->
<script src="/Public/vendor/assets/js/jquery.min.js"></script>
<!--<![endif]-->
<script src="/Public/vendor/assets/js/amazeui.min.js"></script>
<script src="/Public/vendor/assets/js/app.js"></script>

<!--进度条-->
<script src="/Public/vendor/nprogress/nprogress.js"></script>
<script>
  $(function () {
      //进度条
      $(document).ready(function () {
          NProgress.start();
      });

      $(window).load(function () {
          NProgress.done();
      });
  })
</script>


    <script src="/Public/vendor/bootstrapextend/js/bootstrap.extend.js"></script>

    <script charset="utf-8" src="/Public/vendor/validate/jquery.validate.min.js"></script>
    <script charset="utf-8" src="/Public/vendor/validate/localization/messages_zh.js"></script>

    <!-- 配置文件 -->
    <script type="text/javascript" src="/Public/vendor/ueditor/utf8-php/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="/Public/vendor/ueditor/utf8-php/ueditor.all.js"></script>

    <script>
        $(function () {
            //实例化编辑器
            var ue = UE.getEditor('container', {
                initialFrameWidth: 800,//设置编辑器宽度
                initialFrameHeight: 200,//设置编辑器高度
                scaleEnabled: true,
            });

            //js自动验证
            $(".am-form").validate({
                onfocusout: function (element) {
                    $(element).valid();
                }
            });

            //上传单张图片
            $('.upload_one').Huploadify({
                uploader: '<?php echo U("Admin/Uploadfile/upload");?>',
                fileTypeExts: '*.gif;*.jpg;*.jpeg;*.png;*.bmp',
                //fileSizeLimit:{:C('UPLOAD_IMAGE_SIZE')}*1024,
                buttonText: '上 传 图 片',
                onUploadComplete: function (file, data) {
                    data = $.parseJSON(data);
                    $('.view_one img').attr('src', data.real_path);
                    $('.view_one input').attr('value', 'http://oze5mdef4.bkt.clouddn.com/' + data.savename);

                }
            });

            //上传多张
            $('#upload_more').Huploadify({
                uploader: '<?php echo U("Admin/Uploadfile/upload");?>',
                fileTypeExts: '*.gif;*.jpg;*.jpeg;*.png;*.bmp',
//                fileSizeLimit:{:C('UPLOAD_IMAGE_SIZE')}*1024,
                buttonText: '上传多张图片',
                onUploadComplete: function (file, data) {
                    var data = $.parseJSON(data);
                    //console.log(data);
                    if (data.error == 1) {
                        alertMessager(data.message);
                    } else {
                        var input = $('#view_more input');
                        var new_img = '<span class="img-box">' +
                            '<img class="img img-responsive" width="80" src="' + data.real_path + '">' +
                            '<a class="label label-danger remove-picture" href="javascript:void(0);" >删除</a>' +
                            '<input type="hidden" name="gallery[]" value="' + data.real_path + '">' +
                            '</span>';
                        $('#view_more').append(new_img);
                    }
                }
            });

            //删除图片 <i class="glyphicon glyphicon-remove-sign remove-picture"></i>
            $('#view_more').on('click', '.remove-picture', function () {
                var ready_for_remove_id = $(this).closest('.img-box').find('img').attr('data-id'); //获取待删除的图片ID
                if (!ready_for_remove_id) {
                    alertMessager('错误');
                }
                var current_picture_ids = $('#view_more input').val().split(","); //获取当前图集以逗号分隔的ID并转换成数组
                current_picture_ids.remove(ready_for_remove_id); //从数组中删除待删除的图片ID
                $('#view_more input').val(current_picture_ids.join(',')) //删除后覆盖原input的值
                $(this).closest('.img-box').remove(); //删除图片预览图
            });
        })
    </script>


</body>
</html>